package org.swqsbssddqs.shortlink.admin.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.swqsbssddqs.shortlink.admin.common.biz.user.UserContext;
import org.swqsbssddqs.shortlink.admin.common.convention.result.Result;
import org.swqsbssddqs.shortlink.admin.dao.entity.BaseDO;
import org.swqsbssddqs.shortlink.admin.dao.entity.GroupDO;
import org.swqsbssddqs.shortlink.admin.dao.mapper.GroupMapper;
import org.swqsbssddqs.shortlink.admin.dto.req.RecycleBinRecoverReqDTO;
import org.swqsbssddqs.shortlink.admin.dto.req.RecycleBinRemoveReqDTO;
import org.swqsbssddqs.shortlink.admin.dto.req.RecycleBinSaveReqDTO;
import org.swqsbssddqs.shortlink.admin.dto.req.ShortLinkRecycleBinPageReqDTO;
import org.swqsbssddqs.shortlink.admin.remote.ShortLinkActualRemoteService;
import org.swqsbssddqs.shortlink.admin.remote.ShortLinkRemoteService;
import org.swqsbssddqs.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import org.swqsbssddqs.shortlink.admin.service.GroupService;
import org.swqsbssddqs.shortlink.admin.service.RecycleBinService;

import java.util.List;
import java.util.stream.Stream;

@Service(value = "recycleBinServiceImplByAdmin")
@RequiredArgsConstructor
public class RecycleBinServiceImpl implements RecycleBinService {
    private final ShortLinkActualRemoteService shortLinkActualRemoteService;

    private final GroupMapper groupMapper;
    private final StringRedisTemplate stringRedisTemplate;

    public void saveRecycleBin(RecycleBinSaveReqDTO requestParam){
        shortLinkActualRemoteService.saveRecycleBin(requestParam);
    }

    @Override
    public Result<Page<ShortLinkPageRespDTO>> pageRecycleBinShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
        LambdaQueryWrapper<GroupDO> eq = Wrappers.lambdaQuery(GroupDO.class)
                .eq(GroupDO::getUsername, UserContext.getUsername())
                .eq(BaseDO::getDelFlag, 0);
        List<String> gidList = groupMapper.selectList(eq).stream().map(GroupDO::getGid).toList();
        requestParam.setGidList(gidList);
        return shortLinkActualRemoteService.pageRecycleBinShortLink(requestParam.getGidList(),requestParam.getCurrent(),requestParam.getSize());

    }

    @Override
    public void recoverRecycleBin(RecycleBinRecoverReqDTO requestParam) {
        shortLinkActualRemoteService.recoverRecycleBin(requestParam);
    }

    @Override
    public void removeRecycleBin(RecycleBinRemoveReqDTO requestParam) {
        shortLinkActualRemoteService.removeRecycleBin(requestParam);
    }

    ;
}
